package licode.unisop.client.feign;

import licode.unisop.client.info.SopIdInfo;
import licode.unisop.client.info.SopPlatAuthInfo;
import licode.unisop.client.info.SopPlatHeartInfo;
import licode.unisop.client.utils.SopAuthConst;
import licode.unisop.client.utils.SopResult;
import licode.unisop.client.vo.SopAuthPlatform;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 平台对外接口封装
 *
 * @author licode
 */
@FeignClient(name = "${uni-sop.service:uni-platform-service}", url = "${uni-sop.host:}")
public interface SopPlatformAuthFeign {
    @PostMapping("/plat-api/v1/internal/auth/register")
    SopResult<SopAuthPlatform> register(@RequestBody SopPlatAuthInfo req);

    /**
     * 检查平台token是否可用
     *
     * @param req 平台token
     * @return 有效返回true；否则false
     */
    @PostMapping("/plat-api/v1/internal/auth/from-token")
    SopResult<SopAuthPlatform> fromToken(@RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
                                         @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
                                         @RequestBody SopIdInfo req);

    @PostMapping("/plat-api/v1/internal/auth/from-id")
    SopResult<SopAuthPlatform> fromId(@RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
                                      @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
                                      @RequestBody SopIdInfo req);

    /**
     * 获取当前已经认证的平台数
     *
     * @return 认证的平台数
     */
    @PostMapping("/plat-api/v1/internal/auth/auth-count")
    SopResult<Long> getAuthCount(@RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
                                 @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId);

    @PostMapping("/plat-api/v1/internal/auth/forbid")
    SopResult<String> forbid(@RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
                             @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
                             @RequestBody SopIdInfo req);

    @PostMapping("/plat-api/v1/internal/auth/renew-duration")
    SopResult<String> renew(@RequestParam(SopAuthConst.MODAL_TOKEN) String mToken,
                            @RequestParam(SopAuthConst.PLATFORM_TOKEN) String platformId,
                            @RequestBody SopPlatHeartInfo req);
}
